package com.demo.core.exception;

import com.demo.core.entity.R;
import org.jboss.resteasy.reactive.RestResponse;
import org.jboss.resteasy.reactive.server.ServerExceptionMapper;

public class GlobalExceptionHandler {

    @ServerExceptionMapper
    public RestResponse<R> handelBizException(BizException bizException){
        R objectR = new R<>();
        objectR.setCode(bizException.code);
        objectR.setMsg(bizException.msg);
        return RestResponse.status(RestResponse.Status.INTERNAL_SERVER_ERROR,objectR);
    }

    @ServerExceptionMapper
    public RestResponse<R> handelException(Exception bizException){
        R objectR = new R<>();
        objectR.setCode(1);
        objectR.setMsg(bizException.getMessage());
        return RestResponse.status(RestResponse.Status.INTERNAL_SERVER_ERROR,objectR);
    }
}
